package com.subaiqiao.yunshiyuan.entrance.ysy.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subaiqiao.yunshiyuan.basis.mapper.BasisMapper;
import com.subaiqiao.yunshiyuan.entrance.ysy.pojo.ProductCategory;
import com.subaiqiao.yunshiyuan.entrance.ysy.vo.ProductCategoryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@Mapper
public interface ProductCategoryMapper extends BasisMapper<ProductCategory> {

    @Select("SELECT *, " +
            "b.product_category_name productCategoryParentName " +
            "FROM product_category " +
            "LEFT JOIN product_category b on b.product_category_id=product_category.product_category_parent_id ${ew.customSqlSegment}")
    List<ProductCategoryVO> getProductCategoryVO(Page<ProductCategoryVO> page,@Param(Constants.WRAPPER) QueryWrapper<ProductCategoryVO> wrapper);

    @Select("SELECT COUNT(*) FROM product_category")
    Integer FindProductCategoryCount();

    @Select("SELECT COUNT(*) FROM product_category WHERE product_category_parent_id is NULL")
    Integer FindProductCategoryParentCount();
}
